package com.job.core.register.impl;

import javax.sql.DataSource;

import com.job.core.register.RegistHandlerHelper;
import com.job.core.util.DBUtil;
/**
 * 
 * @Title: RegistHandlerHelperImpl.java
 * @Package: com.job.core.register.impl
 * @Description: 注册实现
 * @author: sunwei
 * @date: 2017年5月10日 下午2:29:35
 * @version: V1.0
 */
public class RegistHandlerHelperImpl implements RegistHandlerHelper {
    private DataSource dataSource;

    public void setDataSource(DataSource dataSource) {
        this.dataSource = dataSource;
    }
    /**
     * 
     * @Title: registry
     * @Description:
     * @author:sunwei
     * @createTime:2017年5月10日下午3:11:21
     * @see com.job.core.register.RegistHandlerHelper#registry(java.lang.String, java.lang.String, java.lang.String)
     * @param registGroup
     * @param registryKey
     * @param registryValue
     * @return
     */
    @Override
    public int registry(String registGroup, String registryKey,String registryValue) {
	String updateSql = "UPDATE XXL_JOB_QRTZ_TRIGGER_REGISTRY SET `update_time` = NOW() WHERE `registry_group` = ? AND `registry_key` = ? AND `registry_value` = ?";
	String insertSql = "INSERT INTO XXL_JOB_QRTZ_TRIGGER_REGISTRY( `registry_group` , `registry_key` , `registry_value`, `update_time`) VALUES(? , ? , ?, NOW())";
	int ret = DBUtil.update(dataSource, updateSql, new Object[] {registGroup, registryKey, registryValue });
	if (ret < 1) {
	    ret = DBUtil.update(dataSource, insertSql, new Object[] {registGroup, registryKey, registryValue });
	}
	return ret;
    }

}
